﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    Layout = "~/Views/Shared/_Main.cshtml";

    int productId = ViewBag.productiId == null ? 0 : ViewBag.productiId;
    Product product = ViewBag.product == null ? new Product() : ViewBag.product;
    ViewBag.Title = product.ProductName;
    int areaCode = ViewBag.AreaCode == null ? 0 : ViewBag.AreaCode;

    ItemListBox<OrderDetail> orderDetails = ViewBag.saleRecord;
    ItemListBox<Appraise> appraiselist = ViewBag.appraiselist;
    DateTime hisDate = new DateTime(1970, 1, 1);
    double serverDate = (DateTime.Now - hisDate).TotalSeconds;
    bool IsUnderstock = ViewBag.IsUnderstock;
    int productRemain = ViewBag.ProductRemain;

    double totalAppraise = ViewBag.totalAppraise == null ? 5.0d : ViewBag.totalAppraise;
    string Satisfaction = ViewBag.Satisfaction == null ? "100%" : ViewBag.Satisfaction;

    int IsViewAppriaseBtn = ViewBag.IsViewAppriaseBtn == null ? 0 : ViewBag.IsViewAppriaseBtn;

    int DelAuthenticate = ViewBag.DelAuthenticate == null ? 0 : ViewBag.DelAuthenticate;

    int islogin = 1;
    var loginUrl = "";
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        islogin = 0;
        string tourl = System.Web.HttpContext.Current.Request.RawUrl;
        loginUrl = "/account/login?returnurl=" + System.Web.HttpContext.Current.Server.UrlEncode(tourl);
    }

    int userRole = ViewBag.userRole == null ? 1 : ViewBag.userRole;
    
}
@section head
{
    <script type="text/javascript">

          function submitform() {
              document.forms["buyproduct"].submit();
          }

          function changeNum() {
              // alert(id + price);
              var num = $("#buyCount").val();
              if (num == "" || num <= 0) {
                  $("#buyCount").val("1");
                   
                  alert("数量不能为空且必须大于等于1");
              }
              else if(num>@productRemain)
              {
                    $("#buyCount").val(@productRemain);
                    alert("库存不足,仅剩"+@productRemain+"件");
              }
              
          }
           function doAppraise()
          {
              var obj=$("#doAppraise");
              var classstr= obj.attr("class").toString();
              if(classstr=="Hide")
              {
                obj.removeClass("Hide");
                obj.addClass("View");
                obj.css("display","block");
              }
              else
              {
                obj.removeClass("View");
                obj.addClass("Hide");
                obj.css("display","none");
              }
          }     
        
　　            function addcart()
                { 
                  var verValues ="";
                   $("input[name='verValues']:[checked]").each(function(){
                    var value=$(this).val();
                    verValues=verValues+value+",";
                   });
                  
                 $.post("/Shop/AddProductToCart",{ verNames: null,verValues: verValues,
　　                productid:$("#productid").val(),
　　                buycount:$("#buyCount").val()}, function (response){
                    $("#cart").html(response.split('^')[0]);
                    $("#shoppingcartitem").html(response.split('^')[1]);
                });
                alert("亲，加入购物车成功。");
                return false;
　　            
　　          }
　　      

    </script>
}
<!--#主菜单-->
<div class="container">
    <ul class="breadcrumb">
        <li><a href="/home/index">首页</a> <span class="divider">></span></li>
        <li><a href="/shop/PackagesProducts">套餐列表</a> <span class="divider">></span></li>
        <li class="active">@product.ProductName</li>
    </ul>
    <!--//////////////////////////////////////////////////////////////////////////////////-->
    <div class="row">
        <div class="span9" style="width: 96%">
            <div class="row-fluid">
                <div class="span6 covers">
                    <!--封面大小:350x240-->
                    @{
                        if (product.Images != null && product.Images != "")
                        {
                            var imgStr = product.Images.Split(';')[0];
                        <img style="width:450px; height:300px;min-width:450px; min-height:300px;" class="cover" src="@imgStr" />
                        }
                        else
                        {
                        <img class="cover" src="" />
                        }
                    }
                    <!--/////////////////////////////////-->
                    <div class="share">
                        <!-- JiaThis Button BEGIN -->
                        <div class="jiathis_style_32x32">
                            <a class="jiathis_button_qzone"></a><a class="jiathis_button_tsina"></a><a class="jiathis_button_tqq">
                            </a><a class="jiathis_button_renren"></a><a class="jiathis_button_kaixin001"></a>
                            <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis"
                                target="_blank"></a><a class="jiathis_counter_style"></a>
                        </div>
                        <!-- JiaThis Button END -->
                    </div>
                </div>
                <div class="span6 details">
                    <form action="/shop/DirectPurchase" method="post" name="buyproduct" id="buyproduct">
                    <input type="hidden" id="productid" name="productid" value="@productId" />
                    <input type="hidden" id="areaCode" name="areaCode" value="@areaCode" />
                    <div class="details" style="vertical-align: top">
                        <h4>
                            @product.ProductName</h4>
                        <div style="margin-bottom: 10px;">
                            <span class="key">销量：</span><span><strong>@product.SaleCount</strong> 件</span><span
                                class="muted"> [剩余 @productRemain 件]</span></div>
                        <div style="margin-bottom: 10px;">
                            <span class="key">评价：</span><span><strong>@totalAppraise</strong> 分</span></div>
                        @{
                            if (product.Version != null && product.Version != "")
                            {
                                string[] verArray = product.Version.Split(';');
                                int j = 0;
                                string checkStr = "checked=\"checked\"";
                                string verSionStr = "";
                                foreach (var item in verArray)
                                {
                                    var verName = item.Split('#')[0];
                                    var verValue = item.Split('#')[1];
                                    verSionStr = verName + " [" + verValue.Replace("|", ",") + "]";
                                    if (j == 0)
                                    {
                                        checkStr = "checked=\"checked\"";
                                    }
                                    else
                                    {
                                        checkStr = "";
                                    }
                                    
                            <div style="margin-bottom: 10px;">
                                <input type="radio" name="verValues" value="@verSionStr" @checkStr/>
                                <span class="key">@verName：</span>
                                <input type="hidden" name="verNames" value="@verSionStr"/>
                                <span>
                                    @{
                                    if (verValue != "")
                                    {
                                        string[] verValueArray = verValue.Split('|');

                                        foreach (var valueItem in verValueArray)
                                        {
                                        <span>&nbsp;&nbsp;@valueItem</span>                                            
                                        }
                                    }
                                    }
                                </span>
                            </div>
                                    j++;
                                }
                            }
                        }
                        <div style="margin-bottom: 10px; margin-top: 10px">
                            <span class="key" style="vertical-align: middle">购买数量：</span><span><input type="text"
                                id="buyCount" name="buyCount" onkeyup="changeNum()" maxlength="5" style="height: 12px"
                                class="integer topic" value="1" />
                                件</span>
                            @{
                                if (IsUnderstock == false)
                                {
                                <span style="color: Red">库存不足,仅剩 @productRemain 件</span>
                                }
                            }
                        </div>
                        <div id="submitbtn" style="margin-bottom: 10px;">
                            @{
                                var disable = "";
                                if (userRole != 1 || productRemain <= 0)
                                {
                                    disable = "disabled=\"disabled\"";
                                }


                                if (islogin == 1)
                                {
                                <button type="button" onclick="submitform()" class="btn btn-danger"  @disable>
                                    <span class="icon-ok icon-white"></span>&nbsp;立即购买</button>@Html.Raw("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")<button type="button"  onclick="addcart();return false;" id="topcart" class="btn btn-success"  @disable>
                                        <span class="icon-shopping-cart icon-white"></span>&nbsp;加入购物车</button>
                                }
                                else
                                {
                                <a  href="@loginUrl"  class="btn btn-danger"  @disable><span class="icon-ok icon-white">
                                </span>&nbsp;立即购买</a>@Html.Raw("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")<button type="button" onclick="addcart();return false;" id="topcart" class="btn btn-success"  @disable>
                                    <span class="icon-shopping-cart icon-white"></span>&nbsp;加入购物车</button>
                                }
                            }
                        </div>
                    </div>
                    </form>
                </div>
            </div>
            <div class="clearfix">
                &nbsp;
            </div>
            <div class="tabbable">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab1" data-toggle="tab">商品详情</a></li>
                    <li><a href="#tab2" data-toggle="tab">商品评论</a></li>
                    <li><a href="#tab3" data-toggle="tab">销售记录</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab1" style="overflow: hidden">
                        <p>
                            <!--////////////内容开始/////////////////////-->
                            @Html.Raw(product.Description)
                            <!--////////////内容结束/////////////////////-->
                        </p>
                    </div>
                    <div class="tab-pane" id="tab2">
                        <p>
                            <div class="eval">
                                商品与描述相符<span class="rate">@totalAppraise</span>分&nbsp;&nbsp;@*<span class="muted">[购买商品用户登录可参与评价]</span>*@
                               @* @{
                                    if (IsViewAppriaseBtn == 1)
                                    {
                                    <a href="javascript: doAppraise()" class="btn btn-danger" style="margin-left: 50px;">
                                        <span class="icon-edit icon-white"></span>&nbsp;我要评论</a>
                                    }
                                }*@
                            </div>
                           @* @{
                                if (IsViewAppriaseBtn == 1)
                                {   
                                <div id="doAppraise" class="Hide" style="overflow: hidden; display: none">
                                    <h4 class="border-bottom-gray red bg-bar">
                                        &nbsp;&nbsp;我要评价</h4>
                                    <div class="padding-h-10">
                                        <form action="/shop/Appraise" method="post">
                                        <input type="hidden" value="@productId" name="pid" />
                                        <input type="hidden" value="@areaCode" name="areaCode" />
                                        <div class="row-fluid">
                                            <div>
                                                评分：<span><input type="radio" value="5" checked="checked" name="appraiseGrade" />非常满意</span>
                                                &nbsp;&nbsp;<span><input type="radio" value="4" name="appraiseGrade" />满意</span>
                                                &nbsp;&nbsp;<span><input type="radio" value="2" name="appraiseGrade" />一般</span>
                                                &nbsp;&nbsp;<span><input type="radio" value="1" name="appraiseGrade" />不满意</span>
                                                &nbsp;&nbsp;<span><input type="radio" value="0" name="appraiseGrade" />非常不满意</span>
                                            </div>
                                            <br />
                                            <textarea style="width: 99%" name="appraiseContent"></textarea>
                                            <br />
                                            <div class="text-center">
                                                <input type="submit" class="btn btn-danger" value="确定" /></div>
                                        </div>
                                        </form>
                                    </div>
                                </div>
                                }
                            
                            }*@
                            @{
                                if (appraiselist != null && appraiselist.Data != null && appraiselist.Data.Any())
                                {
                                    foreach (var Item in appraiselist.Data)
                                    {
                                        string date = Item.AppraiseDate.ToString("yyyy-MM-dd HH:mm:ss");
                                <div class="line-dot">
                                    &nbsp;
                                </div>
                                <div class="padding-h-10">
                                    <div class="row-fluid">
                                        <div class="span8 muted">
                                            @Item.user.NickName &nbsp;&nbsp;&nbsp;@date &nbsp;&nbsp;&nbsp;
                                            @{
                                        if (DelAuthenticate == 1)
                                        {
                                                <a href="/shop/DelAppraise?id=@Item.Id&type=0&productid=@productId&areaCode=4" class="btn btn-danger btn-mini">
                                                    删除</a>
                                        }
                                            }
                                        </div>
                                        <div class="span4 text-right">
                                            @{
                                        for (int i = 0; i < Item.AppraiseGrade; i++)
                                        {
                                                <img src="/content/img/star.png" />
                                        }
                                            }
                                        </div>
                                    </div>
                                    <small>@Item.AppraiseContent
                                    </small>
                                </div>
                                       
                                    }
                                }
                            }
                            <!--分页-->
                            <div class="pagination text-right">
                                <a href="/shop/ProductAppraises?id=@productId" target="_blank">更多评价>></a>
                            </div>
                            <!--#分页-->
                        </p>
                    </div>
                    <div class="tab-pane" id="tab3">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>
                                        买家
                                    </th>
                                    <th>
                                        价格
                                    </th>
                                    <th>
                                        数量
                                    </th>
                                    <th>
                                        购买时间
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    if (orderDetails != null && orderDetails.Data != null && orderDetails.Data.Any())
                                    {
                                        foreach (var item in orderDetails.Data)
                                        {
                                            string orderdate = item.order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss");
                                    <tr>
                                        <td>
                                            @item.user.NickName
                                        </td>
                                        <td>
                                            @item.Price
                                        </td>
                                        <td>
                                            @item.Num
                                        </td>
                                        <td>
                                            @orderdate
                                        </td>
                                    </tr>
                                        }
                                    }
                                }
                            </tbody>
                        </table>
                        <!--分页-->
                        <div class="pagination text-right">
                            <a href="/shop/ProductSaleRecords?id=@productId" target="_blank">更多记录>></a>
                        </div>
                        <!--#分页-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
